//import { reject, resolve } from "core-js/fn/promise"
import {$login as loginApi} from '@/api/loginapi'
export default{
    namespaced: true,
    state: () => ({
        token: localStorage.getItem('token') || ''
    }),
    mutations: {
        setToken(state,token){
            state.token =token
            localStorage.setItem('token',token)
        }
    },
    actions:{
        login({commit},userinfo){
            return new Promise((resolve,reject)=>{
                loginApi(userinfo).then(res => {
                    console.log("token1",res)
                    commit('setToken',res.token)
                    router.replace('/')
                    resolve()
                }).catch(err => {
                    reject(err)
                })
            })
        }
    }
}